<template>
  <el-dialog
    append-to-body="true"
    :title="dialogProps.title"
    :visible.sync="dialogProps.visible"
    width="560px"
    @open="handleDialogOpen()"
    v-loading="loading"
  >
    <div slot="title" class="dialog-header">{{ dialogProps.title }}</div>
    <el-form
      :model="integralGradeModel"
      ref="integralGradeForm"
      label-width="80px"
      label-position="right"
      size="small"
    >
      <el-tabs type="border-card" v-model="activeTabName">
        <el-tab-pane
          name="integralGradeInfoTab"
          label="基本信息"
          class="integralGrade-info-tab-pane"
        >
          <el-form-item label="借款额度">
            <el-col :span="16"
              ><el-input
                :maxlength="32"
                v-model="integralGradeModel.borrowAmount"
              ></el-input
            ></el-col>
          </el-form-item>

          <el-form-item label-width="100px" label="积分区间开始">
            <el-col :span="16"
              ><el-input-number
                v-model="integralGradeModel.integralStart"
                :min="0"
            /></el-col>
          </el-form-item>
          <el-form-item label-width="100px" label="积分区间结束">
            <el-col :span="16"
              > <el-input-number
                v-model="integralGradeModel.integralEnd"
                :min="0"
            /></el-col>
          </el-form-item>
        </el-tab-pane>
        <el-tab-pane
          name="q"
          label="基本信息A"
          class="integralGrade-info-tab-pane"
        >
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="handleDialogClose()">取 消</el-button>
      <el-button
        type="primary"
        size="small"
        @click="submitForm('integralGradeForm')"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import { update } from "@/api/integralGrade";
export default {
  name: "integralGrade-edit",
  data() {
    return {
      param: new URLSearchParams(),
      testx: { id: 1, name: "test" },
      loading: false,
      integralGradeModel: {
        id: 0,
        borrowAmount: 0,
        integralStart: 0,
        integralEnd: 0,
      },
      dialogProps: {
        visible: false,
        action: "",
        title: "",
      },
      activeTabName: "integralGradeInfoTab",
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.doUpdateintegralGrade();
        } else {
          return false;
        }
      });
    },
    doUpdateintegralGrade() {
      update(this.integralGradeModel)
        .then((response) => {
          this.$message.success(response.data.message);
        })
        .catch((error) => {
          console.log("修改失败！", error);
        });
      this.dialogProps.visible = false;
    },
    handleDialogClose() {
      this.dialogProps.visible = false;
    },
    handleDialogOpen() {
      this.$nextTick(() => {
        this.$refs["integralGradeForm"].clearValidate();
      });
    },
    outputError(error) {
      console.log(error.response ? error.response : error.message);
      this.loading = false;
      this.$message({
        showClose: true,
        message: "出错了，请按F12查看浏览器日志。",
        type: "error",
      });
    },
  },
  mounted: function () {
    this.$nextTick(() => {
      this.$on("openEditintegralGradeDialog", function (integralGrade) {
        this.integralGradeModel = integralGrade;
        this.dialogProps.action = "edit";
        this.dialogProps.title = "修改积分等级";
        this.activeTabName = "integralGradeInfoTab";
        this.dialogProps.visible = true;
      });
    });
  },
};
</script>

<style lang="scss" scoped>
.integralGrade-info-tab-pane {
  margin-top: 10px;
}
</style>





